package com.wenhai.leetcode.linkedList;

/**
 * @ClassName _160相交链表
 * @Description https://leetcode-cn.com/problems/intersection-of-two-linked-lists/
 * @Author 谢文海
 * @Date 2021/4/4 20:18
 * @Version 1.0
 **/
public class _160相交链表 {
    public ListNode getIntersectionNode(ListNode headA, ListNode headB) {
        if (headA == null | headB == null) {
            return null;
        }
        ListNode curA = headA;
        ListNode curB = headB;
        while (curA != curB) {
            curA = curA == null ? headB : curA.next;
            curB = curB == null ? headA : curB.next;
        }
        return curA;
    }


    public class ListNode {
        int val;
        ListNode next;

        ListNode(int x) {
            val = x;
            next = null;
        }
    }
}
